package com.fuluwa.domain.product.model;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.fuluwa.domain.shared.AbstractIdMantainceDomainObject;
import com.google.common.collect.Lists;

@Entity
@Table(name = "p_category")
public class Category extends AbstractIdMantainceDomainObject {
	public static enum CategoryStatus {
		ENABLE, DISABLE
	}

	private String name;
	private int level = 1;
	@Enumerated(EnumType.STRING)
	private CategoryStatus status = CategoryStatus.ENABLE;
	@ManyToOne
	private Category parnet;
	@OneToMany(mappedBy = "parnet")
	private List<Category> childrens=Lists.newArrayList();

	// @OneToMany(mappedBy = "category")
	// private List<CategoryAttribute> categoryAttrs;

	private Category() {
	}
	

	public Category(Long id) {
		super(id);
	}


	public Category(String name, int level, Category parnet) {
		super();
		this.name = name;
		this.level = level;
		this.parnet = parnet;
		if(parnet!=null)
		parnet.addChildrens(this);
	}

	// public Category(String name, int level, Category parnet, List<Category>
	// childrens,
	// List<CategoryAttribute> categoryAttrs) {
	// this.name = name;
	// this.level = level;
	// this.parnet = parnet;
	// this.childrens = childrens;
	// this.categoryAttrs = categoryAttrs;
	// }

	public List<Category> getChildrens() {
		return childrens;
	}

	public void addChildrens(Category childrens) {
		this.childrens.add(childrens);
	}

	public void removeChildrens(Category childrens) {
		this.childrens.remove(childrens);
	}

	// public List<CategoryAttribute> getCategoryAttrs() {
	// return categoryAttrs;
	// }
	//
	// public void addCategoryAttr(CategoryAttribute categoryAttr) {
	// this.categoryAttrs.add(categoryAttr);
	// }
	// public void removeCategoryAttr(CategoryAttribute categoryAttr) {
	// this.categoryAttrs.remove(categoryAttr);
	// }

	public String getName() {
		return name;
	}

	public int getLevel() {
		return level;
	}

	public CategoryStatus getStatus() {
		return status;
	}

	public Category getParnet() {
		return parnet;
	}

}
